package com.orzxlee.Lambda04;

import com.orzxlee.Lambda03.Flyable;

/**
 * 练习3:
 *      1.定义一个接口Addable,定义方法int add(int x,int y);
 *      2.定义一个测试类AddableDemo
 *          方法:useAddable(Addable a)
 *
 * 练习4:
 *      省略模式
 *
 *
 */
public class AddableDemo {
    public static void main(String[] args) {

        //匿名内部类
        useAddable(new Addable() {
            @Override
            public int add(int x, int y) {
                return x+y;
            }
        });


        //1.Lambda表达式
        useAddable((x, y) -> {
            return x + y;
        });

        //2.如果代码块只有一条语句可以省略{};
        useFlyable(s -> System.out.println(s));

        //3.如果代码块中只由一条语句,return也可以省略掉
        useAddable((x, y) -> x + y);


    }

    private static void useFlyable(Flyable f){
        f.fly("起风了");

    }
    private static void useAddable(Addable a){
       int num =  a.add(1,3);
        System.out.println(num);
    }
}
